window.onload = function() {
	//关注游戏管理  开始
	//创建纵向图标的函数
	var Att_iconArr = ["AfocusImg/img1.png",
		"AfocusImg/img2.png",
		"AfocusImg/img3.png",
		"AfocusImg/img4.png",
		"AfocusImg/img5.png",
		"AfocusImg/img6.png",
		"AfocusImg/img1.png",
		"AfocusImg/img2.png",
		"AfocusImg/img3.png",
		"AfocusImg/img4.png",
		"AfocusImg/img5.png",
		"AfocusImg/img6.png"
	];
	var Att_iconTitle = ["天涯明月刀", "天天酷跑", "英雄联盟", "大话西游", "天涯明月刀", "天天酷跑", "英雄联盟", "大话西游", "天涯明月刀", "天天酷跑", "英雄联盟", "大话西游"];
	for(var i = 0; i < Att_iconArr.length; i++) {
		var icon = Att_createIcon(Att_iconArr[i], Att_iconTitle[i], i);
		$(".b_AttWrap").append(icon);
	}
	//创建关注游戏管理函数
	function Att_createIcon(imageSrc, title, index) {
		return $("<li class='b_Attlist' data-id=" + index + "><div class='b_AttimgBox'><img src=" + imageSrc + " class='b_Attimg'/></div><div class='b_Attinfo'><span class='b_Attfont1'>" + title + "</span><span class='b_Attfont2'>游戏评级:</span></div><div class='b_AttfocusBox'><button class='b_AttfocusBtn'>关注</button></div></li>")
	};

	//点击关注
	//定义我关注的游戏的数组
	var AttGame = [];
	//点击关注改变颜色
	$(".b_AttfocusBtn").on("touchend", function() {
		var text = $(this).text();
		if(text == "关注") {
			$(this).css({
				backgroundColor: "#FFFFFF",
				color: "#FE786F",
				border: "1px solid #FE786F"
			});
			//获取关注游戏的图标路径
			var imgSrc = $(this).parent().parent().find(".b_Attimg").attr("src");
			//获取关注游戏的游戏名
			var imgName = $(this).parent().parent().find(".b_Attfont1").text();
			//获取关注游戏的自定义id
			var imgId = $(this).parent().parent().attr("data-id");
			//创建关注游戏信息对象
			var infoObj = {
				src: imgSrc,
				name: imgName,
				id: imgId
			};
			AttGame.push(infoObj);
			$(this).text("取消关注");
		} else {
			$(this).css({
				backgroundColor: "#FE786F",
				color: "#FFFFFF",
				border: "none"
			});
			//取消关注,从关注游戏数组中删除
			//获取关注游戏的自定义id
			var imgId = $(this).parent().parent().attr("data-id");
			$.each(AttGame, function(index) {
				if(this.id == imgId) {
					AttGame.splice(index, 1);
				};
			});
			$(this).text("关注");
		};
		//向loclaStorage推送数组
		localStorage.AttGame = JSON.stringify(AttGame);
	});
	//关注游戏管理  结束
 
	//点击刷新使得关注过的游戏依然显示为关注
	//首先获取到数据库里所有的关注id 并对其循环
	if(localStorage.AttGame != undefined) {
		var localAttGame = JSON.parse(localStorage.AttGame);
		AttGame = localAttGame;
		for(var i = 0; i < localAttGame.length; i++) {
			var id = localAttGame[i].id;
			$.each($(".b_Attlist"), function() {
				var index = $(this).attr("data-id");
				if(index == id) {
					$(this).find(".b_AttfocusBtn").css({
						backgroundColor: "#FFFFFF",
						color: "#FE786F",
						border: "1px solid #FE786F"
					});
					$(this).find(".b_AttfocusBtn").text("取消关注")
				}
			})
		}
	}

	//点击返回按钮  回到首页
	$(".b_navImgBack").on("touchend", function() {
		window.location.href = "Aindex01.html";
	});
}